package com.example.springbootpay.service;

public abstract class AbstractPaymentTemplate {
    // 模板方法定义支付流程
    public final String processPayment(Integer amount) {
        validateAmount(amount);
        String orderId = generateOrderId();
        return doUnifiedOrder(orderId, amount);
    }

    private void validateAmount(Integer amount) {
        if (amount == null || amount <= 0) {
            throw new IllegalArgumentException("支付金额不合法");
        }
    }

    private String generateOrderId() {
        return "PAY" + System.currentTimeMillis();
    }

    // 抽象方法由子类实现
    protected abstract String doUnifiedOrder(String orderId, Integer amount);
    public abstract String doOrderQuery(String orderId);
    public abstract String doRefund(String orderId, Integer amount);
}